package com.px.controller;

import com.px.mapper.OrderDao;
import com.px.mapper.ShGoodsTempStockDao;
import com.px.pojo.ShGoodsTempStock;
import com.px.pojo.ShOrder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ProviderOrderController {

    @Resource
    private OrderDao orderDao;

    @Resource
    private ShGoodsTempStockDao shGoodsTempStockDao;


    //根据用户Id查询订单列表
    @PostMapping("/api/provider/order/selectOrderByUserId")
    List<ShOrder> selectOrderByUserId(@RequestParam Integer userId) throws Exception{
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        return orderDao.selectOrderList(map);
    }

    @PostMapping("/api/provider/order/selectOrderByOrderId")
    ShOrder selectOrderByOrderId(@RequestParam Integer orderId) throws Exception{
        return orderDao.selectOrderByOrderId(orderId);
    }

    //根据订单号查询订单对象
    @PostMapping("/api/provider/order/selectOrderByOrderNo")
    ShOrder selectOrderByOrderNo(@RequestParam String orderNo) throws Exception{
        return orderDao.selectOrderByOrderNo(orderNo);
    }

    @PostMapping("/api/provider/order/updateOrder")
    Integer updateOrder(@RequestBody ShOrder shOrder) throws Exception{
        return orderDao.updateOrder(shOrder);
    }

    @PostMapping("/api/provider/goodsTempStock/updateStock")
    Integer updateStock(@RequestBody ShGoodsTempStock shGoodsTempStock) throws Exception{
        return shGoodsTempStockDao.updateStock(shGoodsTempStock);
    }

    @PostMapping("/api/provider/goodsTempStock/selectGoodsTempStock")
    ShGoodsTempStock selectGoodsTempStock(@RequestParam Integer id) throws Exception{
        return shGoodsTempStockDao.selectGoodsTempStockById(id);
    }

}
